﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwNc_Po_DobavljacuProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwNc_Po_DobavljacuProviderBaseCore : EntityViewProviderBase<VwNc_Po_Dobavljacu>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwNc_Po_Dobavljacu&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwNc_Po_Dobavljacu&gt;"/></returns>
		protected static VList&lt;VwNc_Po_Dobavljacu&gt; Fill(DataSet dataSet, VList<VwNc_Po_Dobavljacu> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwNc_Po_Dobavljacu>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwNc_Po_Dobavljacu&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwNc_Po_Dobavljacu>"/></returns>
		protected static VList&lt;VwNc_Po_Dobavljacu&gt; Fill(DataTable dataTable, VList<VwNc_Po_Dobavljacu> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwNc_Po_Dobavljacu c = new VwNc_Po_Dobavljacu();
					c.IDArtikl = (Convert.IsDBNull(row["IDArtikl"]))?(int)0:(System.Int32?)row["IDArtikl"];
					c.IDOrganizacijaOd = (Convert.IsDBNull(row["IDOrganizacijaOd"]))?(int)0:(System.Int32)row["IDOrganizacijaOd"];
					c.NCDobavljac = (Convert.IsDBNull(row["NCDobavljac"]))?0:(System.Decimal?)row["NCDobavljac"];
					c.Datum = (Convert.IsDBNull(row["Datum"]))?DateTime.MinValue:(System.DateTime)row["Datum"];
					c.ImeKlijenta = (Convert.IsDBNull(row["ImeKlijenta"]))?string.Empty:(System.String)row["ImeKlijenta"];
					c.IDKlijent = (Convert.IsDBNull(row["IDKlijent"]))?(int)0:(System.Int32)row["IDKlijent"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwNc_Po_Dobavljacu&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwNc_Po_Dobavljacu&gt;"/></returns>
		protected VList<VwNc_Po_Dobavljacu> Fill(IDataReader reader, VList<VwNc_Po_Dobavljacu> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwNc_Po_Dobavljacu entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwNc_Po_Dobavljacu>("VwNc_Po_Dobavljacu",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwNc_Po_Dobavljacu();
					}
					entity.IDArtikl = reader.IsDBNull(reader.GetOrdinal("IDArtikl")) ? null : (System.Int32?)reader["IDArtikl"];
					//entity.IDArtikl = (Convert.IsDBNull(reader["IDArtikl"]))?(int)0:(System.Int32?)reader["IDArtikl"];
					entity.IDOrganizacijaOd = (System.Int32)reader["IDOrganizacijaOd"];
					//entity.IDOrganizacijaOd = (Convert.IsDBNull(reader["IDOrganizacijaOd"]))?(int)0:(System.Int32)reader["IDOrganizacijaOd"];
					entity.NCDobavljac = reader.IsDBNull(reader.GetOrdinal("NCDobavljac")) ? null : (System.Decimal?)reader["NCDobavljac"];
					//entity.NCDobavljac = (Convert.IsDBNull(reader["NCDobavljac"]))?0:(System.Decimal?)reader["NCDobavljac"];
					entity.Datum = (System.DateTime)reader["Datum"];
					//entity.Datum = (Convert.IsDBNull(reader["Datum"]))?DateTime.MinValue:(System.DateTime)reader["Datum"];
					entity.ImeKlijenta = (System.String)reader["ImeKlijenta"];
					//entity.ImeKlijenta = (Convert.IsDBNull(reader["ImeKlijenta"]))?string.Empty:(System.String)reader["ImeKlijenta"];
					entity.IDKlijent = (System.Int32)reader["IDKlijent"];
					//entity.IDKlijent = (Convert.IsDBNull(reader["IDKlijent"]))?(int)0:(System.Int32)reader["IDKlijent"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwNc_Po_Dobavljacu"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwNc_Po_Dobavljacu"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwNc_Po_Dobavljacu entity)
		{
			reader.Read();
			entity.IDArtikl = reader.IsDBNull(reader.GetOrdinal("IDArtikl")) ? null : (System.Int32?)reader["IDArtikl"];
			//entity.IDArtikl = (Convert.IsDBNull(reader["IDArtikl"]))?(int)0:(System.Int32?)reader["IDArtikl"];
			entity.IDOrganizacijaOd = (System.Int32)reader["IDOrganizacijaOd"];
			//entity.IDOrganizacijaOd = (Convert.IsDBNull(reader["IDOrganizacijaOd"]))?(int)0:(System.Int32)reader["IDOrganizacijaOd"];
			entity.NCDobavljac = reader.IsDBNull(reader.GetOrdinal("NCDobavljac")) ? null : (System.Decimal?)reader["NCDobavljac"];
			//entity.NCDobavljac = (Convert.IsDBNull(reader["NCDobavljac"]))?0:(System.Decimal?)reader["NCDobavljac"];
			entity.Datum = (System.DateTime)reader["Datum"];
			//entity.Datum = (Convert.IsDBNull(reader["Datum"]))?DateTime.MinValue:(System.DateTime)reader["Datum"];
			entity.ImeKlijenta = (System.String)reader["ImeKlijenta"];
			//entity.ImeKlijenta = (Convert.IsDBNull(reader["ImeKlijenta"]))?string.Empty:(System.String)reader["ImeKlijenta"];
			entity.IDKlijent = (System.Int32)reader["IDKlijent"];
			//entity.IDKlijent = (Convert.IsDBNull(reader["IDKlijent"]))?(int)0:(System.Int32)reader["IDKlijent"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwNc_Po_Dobavljacu"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwNc_Po_Dobavljacu"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwNc_Po_Dobavljacu entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IDArtikl = (Convert.IsDBNull(dataRow["IDArtikl"]))?(int)0:(System.Int32?)dataRow["IDArtikl"];
			entity.IDOrganizacijaOd = (Convert.IsDBNull(dataRow["IDOrganizacijaOd"]))?(int)0:(System.Int32)dataRow["IDOrganizacijaOd"];
			entity.NCDobavljac = (Convert.IsDBNull(dataRow["NCDobavljac"]))?0:(System.Decimal?)dataRow["NCDobavljac"];
			entity.Datum = (Convert.IsDBNull(dataRow["Datum"]))?DateTime.MinValue:(System.DateTime)dataRow["Datum"];
			entity.ImeKlijenta = (Convert.IsDBNull(dataRow["ImeKlijenta"]))?string.Empty:(System.String)dataRow["ImeKlijenta"];
			entity.IDKlijent = (Convert.IsDBNull(dataRow["IDKlijent"]))?(int)0:(System.Int32)dataRow["IDKlijent"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwNc_Po_DobavljacuFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwNc_Po_Dobavljacu"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwNc_Po_DobavljacuFilterBuilder : SqlFilterBuilder<VwNc_Po_DobavljacuColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwNc_Po_DobavljacuFilterBuilder class.
		/// </summary>
		public VwNc_Po_DobavljacuFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwNc_Po_DobavljacuFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwNc_Po_DobavljacuFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwNc_Po_DobavljacuFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwNc_Po_DobavljacuFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwNc_Po_DobavljacuFilterBuilder

	#region VwNc_Po_DobavljacuParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwNc_Po_Dobavljacu"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwNc_Po_DobavljacuParameterBuilder : ParameterizedSqlFilterBuilder<VwNc_Po_DobavljacuColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwNc_Po_DobavljacuParameterBuilder class.
		/// </summary>
		public VwNc_Po_DobavljacuParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwNc_Po_DobavljacuParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwNc_Po_DobavljacuParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwNc_Po_DobavljacuParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwNc_Po_DobavljacuParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwNc_Po_DobavljacuParameterBuilder
} // end namespace
